#Region "Using Directives"

Imports System

#End Region

Namespace C4F.DevKit.Bluetooth.ObjectExchange

    ''' <summary>
    ''' Exception class for Object Exchange operations.
    ''' </summary>
    <Serializable()> _
    Public Class ObjectExchangeException
        Inherits Exception

#Region "Private Fields"

        ''' <summary>
        ''' Specifies the type of error that has occurred.
        ''' </summary>
        Private m_errorType As ObjectExchangeErrorType

#End Region

#Region "Public Properties"

        ''' <summary>
        ''' Gets the type of error that caused the exception to be thrown.
        ''' </summary>
        Public ReadOnly Property ErrorType() As ObjectExchangeErrorType

            Get
                Return Me.m_errorType
            End Get

        End Property

#End Region

#Region "Constructors"

        ''' <summary>
        ''' Initializes the ErrorType property with the specified errorType and 
        ''' sets the Message property of the new instance to a system-supplied
        ''' message.
        ''' </summary>
        ''' <param name="errorType">Type of error that occurred.</param>
        Public Sub New(ByVal errorType As ObjectExchangeErrorType)

            MyBase.New()
            Me.m_errorType = errorType

        End Sub

        ''' <summary>
        ''' Initializes the exception with with the specified errorType and sets
        ''' the Message property to the specified error message.
        ''' </summary>
        ''' <param name="errorType">Type of error that occurred.</param>
        ''' <param name="message">The message that describes the error.
        ''' </param>
        Public Sub New(ByVal errorType As ObjectExchangeErrorType, ByVal message As String)

            MyBase.New(message)
            Me.m_errorType = errorType

        End Sub

        ''' <summary>
        ''' Initializes a new instance of the Exception class with the specified
        ''' errorType, error message and a reference to the inner exception that
        ''' is the cause of this exception.
        ''' </summary>
        ''' <param name="errorType">Type of error that occurred.</param>
        ''' <param name="message">The message that describes the error.</param>
        ''' <param name="innerException">The exception that is the cause of this
        ''' exception.</param>
        Public Sub New(ByVal errorType As ObjectExchangeErrorType, ByVal message As String, ByVal innerException As Exception)

            MyBase.New(message, innerException)
            Me.m_errorType = errorType

        End Sub

        ''' <summary>
        ''' Initializes a new instance of this class with serialized data.
        ''' </summary>
        ''' <param name="info">The SerializationInfo that holds the serialized 
        ''' object data about the exception being thrown.</param>
        ''' <param name="context">The StreamingContext that contains contextual
        ''' information about the source or destination.</param>
        Protected Sub New(ByVal info As Runtime.Serialization.SerializationInfo, ByVal context As Runtime.Serialization.StreamingContext)

            MyBase.New(info, context)
            If info IsNot Nothing Then
                Me.m_errorType = CType(info.GetValue("ErrorType", GetType(ObjectExchangeErrorType)), ObjectExchangeErrorType)
            End If

        End Sub

#End Region

#Region "Overriden Methods"

        ''' <summary>
        ''' Sets the SerializationInfo with information about the exception. 
        ''' </summary>
        ''' <param name="info">The SerializationInfo that holds the serialized 
        ''' object data about the exception being thrown.</param>
        ''' <param name="context">The StreamingContext that contains contextual
        ''' information about the source or destination.</param>
        <Security.Permissions.SecurityPermission(Security.Permissions.SecurityAction.LinkDemand, Flags:=Security.Permissions.SecurityPermissionFlag.SerializationFormatter)> _
        Public Overloads Overrides Sub GetObjectData(ByVal info As Runtime.Serialization.SerializationInfo, ByVal context As Runtime.Serialization.StreamingContext)
            MyBase.GetObjectData(info, context)

            If info IsNot Nothing Then
                info.AddValue("ErrorType", Me.m_errorType)
            End If
        End Sub

#End Region

    End Class

End Namespace
